<template>
	<div class="loging">
		<a-spin size="large" />
	</div>
	<form id="rForm" name="rForm" :action="action" method="post">
		<input type="hidden" name="success" :value="redirect.success" />
		<input type="hidden" name="error" :value="redirect.error" />
		<input type="hidden" name="appid" :value="redirect.appId" />
	</form>
</template>

<script setup name="SinLogin">
import loginApi from '@/api/auth/loginApi'
import sysConfig from '@/config/index'
import { afterLogin, param2Obj, clear } from './util'

const action = ref('')
const showForm = ref(false)
const redirect = reactive({
	success: `${sysConfig.API_URL}/auth/b/ssoSuccess`,
	error: `${sysConfig.API_URL_B}/auth/authFail`,
	appId: sysConfig.APP_ID
})

const getLoginUrl = async () => {
	loginApi.getLoginUrl().then((data) => {
		action.value = data
		nextTick(() => {
			document.forms['rForm'].submit()
		})
	})
}
// 获取链接上的参数来判断是第几次进入
const params = param2Obj()
if (params.access_token) {
	// 登录成功 第二次
	afterLogin(params.access_token)
} else {
	// 第一次
	clear()
	getLoginUrl()
}
</script>

<style scoped lang="less">
.loging {
	width: 100vw;
	height: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
}
</style>
